package com.example.demo.huawei;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

/*
寻找身高相近的小朋友
输入：
100 10
95 96 97 98 99 101 102 103 104 105

输出：
99 101 98 102 97 103 96 104 95 105

 */
public class Main56_2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h1 = scanner.nextInt();
        int n = scanner.nextInt();
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            res.add(scanner.nextInt());
        }
        res.sort(((o1, o2) -> {
            int a = Math.abs(o1 - h1);
            int b = Math.abs(o2 - h1);
            if (a == b) {
                return o1 - o2;
            } else {
                return a - b;
            }
        }));
        res.forEach(
                r -> System.out.print(r + " ")
        );
    }
}
